package com.xq.chrome.web.controller;

import com.xq.chrome.web.other.BaseException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

@Controller
public class OtherController {

  @RequestMapping("/other/test1")
  public String test1(Long id) {
    return "redirect:/user/get/" + id + ".json";
  }

  @RequestMapping("/other/test2")
  public @ResponseBody
  ModelAndView test2(Long id) {
    ModelAndView view = new ModelAndView("redirect:/user/get/2.json");
    return view;
  }

  @RequestMapping("/other/test3")
  public @ResponseBody
  RedirectView test3(Long id) {
    RedirectView view = new RedirectView("/user/get/3.json");
    return view;
  }

  @RequestMapping("/other/test4")
  public String test4(Long id) {
    return "forward:/user/get/4.json";
  }

  /**
   * @api {get} /user/:id Request User information
   * @apiName GetUser
   * @apiGroup User
   * @apiParam {Number} id Users unique ID.
   * @apiSuccess {String} firstname Firstname of the User.
   * @apiSuccess {String} lastname  Lastname of the User.
   * @apiSuccessExample Success-Response:
   * HTTP/1.1 200 OK
   * {
   * "firstname": "John",
   * "lastname": "Doe"
   * }
   * @apiError UserNotFound The id of the User was not found.
   * @apiErrorExample Error-Response:
   * HTTP/1.1 404 Not Found
   * {
   * "error": "UserNotFound"
   * }
   */
  @RequestMapping("/other/test5")
  public String test5(Long id) {
    if (true) {
      throw new BaseException(404, "aaa");
    }
    return "111";
  }

  /**
   * @api {get} /user/:id Request User information
   * @apiName GetUser
   * @apiGroup User
   * @apiParam {Number} id Users unique ID.
   * @apiSuccess {String} firstname Firstname of the User.
   * @apiSuccess {String} lastname  Lastname of the User.
   * @apiSuccessExample Success-Response:
   * HTTP/1.1 200 OK
   * {
   * "firstname": "John",
   * "lastname": "Doe"
   * }
   * @apiError UserNotFound The id of the User was not found.
   * @apiErrorExample Error-Response:
   * HTTP/1.1 404 Not Found
   * {
   * "error": "UserNotFound"
   * }
   */
  public String test() {
    return "";
  }

}
